package chances.epg.ui.taglib.model;

import java.util.HashMap;

import com.google.common.base.Strings;

public class Border implements java.io.Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4342485640639888331L;
	private int top;
	private int left;
	private int right;
	private int bottom;
	public Border(int left2, int top2, int right2, int bottom2) {
		this.left = left2;
		this.top = top2;
		this.right = right2;
		this.bottom = bottom2;
	}
	public Border(int value) {
		this(value,value,value,value);
	}
	public Border() {
		 super();
	}
	public int getTop() {
		return top;
	}
	public void setTop(int top) {
		this.top = top;
	}
	public int getLeft() {
		return left;
	}
	public void setLeft(int left) {
		this.left = left;
	}
	public int getRight() {
		return right;
	}
	public void setRight(int right) {
		this.right = right;
	}
	public int getBottom() {
		return bottom;
	}
	public void setBottom(int bottom) {
		this.bottom = bottom;
	}
	
	public static Border parseStyle(String rectStyle) {
		if(Strings.isNullOrEmpty(rectStyle)){
			return new Border();
		}
		String[] styles = rectStyle.split(";");
		HashMap<String, String> keyvalues = new HashMap<String, String>();
		for (String attrs : styles) {
			String[] keyValue = attrs.split(":");
			if (keyValue.length > 1) {
				keyvalues.put(keyValue[0].trim(), keyValue[1].trim());
			}
		}


		int bottom = Rect.parseInt(keyvalues.get("bottom"));
		int top = Rect.parseInt(keyvalues.get("top"));
		int left = Rect.parseInt(keyvalues.get("left"));
		int right = Rect.parseInt(keyvalues.get("right"));
		Border result = new Border(left, top, right, bottom);
	
		return result;

	}
}
